package com.jbm.jbmsupplier.activity;

import android.os.Handler;
import android.os.Message;
import android.widget.ImageView;
import android.widget.TextView;

import com.handmark.pulltorefresh.library.PullToRefreshListView;
import com.jbm.jbmsupplier.R;
import com.jbm.jbmsupplier.adapter.IncomeAdapter;
import com.jbm.jbmsupplier.net.NetIntent;
import com.jbm.jbmsupplier.utlis.ExitActivity;
import com.jbm.jbmsupplier.view.DialogLoading;
import com.jbm.onehome.iface.IOrder;
import com.jbm.onehome.iface.IOrderCtrl;

import java.util.ArrayList;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by 家帮忙 on 2017/4/11.
 */

public class IncomeActivity extends AllActivityApp {
    @InjectView(R.id.teleft)
    TextView teleft;
    @InjectView(R.id.tetitle)
    TextView tetitle;
    @InjectView(R.id.pull_refresh_list)
    PullToRefreshListView pullRefreshList;
    @InjectView(R.id.lv_default1)
    ImageView lvDefault1;
    ArrayList<IOrder> listpled;
    DialogLoading dialogloading;
    private final int INCOME=0001;
    private IncomeAdapter adapter;

    @Override
    public int setContentView() {
        return R.layout.lz_jinemingxi;
    }

    @Override
    public void initIalizeView() {
        ExitActivity.getInstance().addActivity(this);
        ButterKnife.inject(this);
        listpled = new ArrayList();
        tetitle.setText("收入明细");
        pullRefreshList.setAdapter(adapter=new IncomeAdapter(this,listpled));
        initIncome();
    }
//
//    @Override
//    protected void onCreate(@Nullable Bundle savedInstanceState) {
//        super.onCreate(savedInstanceState);
//        ExitActivity.getInstance().addActivity(this);
//        setContentView(R.layout.lz_jinemingxi);
//        ButterKnife.inject(this);
//        listpled = new ArrayList();
//        tetitle.setText("收入明细");
//        pullRefreshList.setAdapter(adapter=new IncomeAdapter(this,listpled));
//        initIncome();
//    }
    private void initIncome() {
        NetIntent netintent = new NetIntent(handler);
        netintent.setIncoment(INCOME);
        dialogloading = new DialogLoading(this, "加载中....", false);
        dialogloading.show();
    }


    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
switch (msg.what){
    case INCOME:
        listpled.clear();
        IOrderCtrl ipay = (IOrderCtrl)msg.obj;
        if (ipay.m_code==200) {
            setDialogding();
            for (int i = 0; i < ipay.GetCount(); i++) {
                listpled.add(ipay.IndexofList(i));
            }
            adapter.notifyDataSetChanged();

        } else if (ipay.m_info.equals("Not Connect")){
            setDialogding();
            hint(ipay.m_info);
        }else if (ipay.m_code==500){
            setDialogding();
            hint(ipay.m_info);
        }else {
            setDialogding();
//                            hint(ipay.errorinfo);
        }
        break;
}

        }
    };












    public void setDialogding() {
        if (dialogloading != null) {
            dialogloading.dismiss();
        }
    }
    @OnClick(R.id.teleft)
    public void onViewClicked() {
        finish();
    }
}
